﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.EnergyConsumptionRecordVMs
{
    public partial class EnergyConsumptionRecordListVM : BasePagedListVM<EnergyConsumptionRecord_View, EnergyConsumptionRecordSearcher>
    {

        protected override IEnumerable<IGridColumn<EnergyConsumptionRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<EnergyConsumptionRecord_View>>{
                this.MakeGridHeader(x => x.UploadTime),
                this.MakeGridHeader(x => x.stationCode),
                this.MakeGridHeader(x => x.machineCode),
                this.MakeGridHeader(x => x.Airpressure),
                this.MakeGridHeader(x => x.Flow),
                this.MakeGridHeader(x => x.Energy),
                this.MakeGridHeader(x => x.VoltageA),
                this.MakeGridHeader(x => x.VoltageB),
                this.MakeGridHeader(x => x.VoltageC),
                this.MakeGridHeader(x => x.ElectricityA),
                this.MakeGridHeader(x => x.ElectricityB),
                this.MakeGridHeader(x => x.ElectricityC),
                this.MakeGridHeader(x => x.Time),
                this.MakeGridHeader(x => x.Unit),
                this.MakeGridHeader(x => x.acquisitionInterval),
                this.MakeGridHeader(x => x.machineStatus),
                this.MakeGridHeader(x => x.uploadflag),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<EnergyConsumptionRecord_View> GetSearchQuery()
        {
            var query = DC.Set<EnergyConsumptionRecord>()
                .CheckBetween(Searcher.UploadTime?.GetStartTime(), Searcher.UploadTime?.GetEndTime(), x => x.UploadTime, includeMax: false)
                .CheckContain(Searcher.stationCode, x=>x.stationCode)
                .CheckContain(Searcher.machineCode, x=>x.machineCode)
                .CheckContain(Searcher.Airpressure, x=>x.Airpressure)
                .CheckContain(Searcher.Flow, x=>x.Flow)
                .CheckContain(Searcher.Energy, x=>x.Energy)
                .CheckContain(Searcher.VoltageA, x=>x.VoltageA)
                .CheckContain(Searcher.VoltageB, x=>x.VoltageB)
                .CheckContain(Searcher.VoltageC, x=>x.VoltageC)
                .CheckContain(Searcher.ElectricityA, x=>x.ElectricityA)
                .CheckContain(Searcher.ElectricityB, x=>x.ElectricityB)
                .CheckContain(Searcher.ElectricityC, x=>x.ElectricityC)
                .CheckContain(Searcher.Time, x=>x.Time)
                .CheckContain(Searcher.acquisitionInterval, x=>x.acquisitionInterval)
                .CheckContain(Searcher.machineStatus, x=>x.machineStatus)
                .CheckEqual(Searcher.uploadflag, x=>x.uploadflag)
                .Select(x => new EnergyConsumptionRecord_View
                {
				    ID = x.ID,
                    UploadTime = x.UploadTime,
                    stationCode = x.stationCode,
                    machineCode = x.machineCode,
                    Airpressure = x.Airpressure,
                    Flow = x.Flow,
                    Energy = x.Energy,
                    VoltageA = x.VoltageA,
                    VoltageB = x.VoltageB,
                    VoltageC = x.VoltageC,
                    ElectricityA = x.ElectricityA,
                    ElectricityB = x.ElectricityB,
                    ElectricityC = x.ElectricityC,
                    Time = x.Time,
                    Unit = x.Unit,
                    acquisitionInterval = x.acquisitionInterval,
                    machineStatus = x.machineStatus,
                    uploadflag = x.uploadflag,
                })
                .OrderByDescending(x => x.ID);
            return query;
        }

    }

    public class EnergyConsumptionRecord_View : EnergyConsumptionRecord{

    }
}
